package com.rykj.qxj.monitor.util;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.Setter;

@Getter
@Setter
@ApiModel(description = "返回结果")
public final class Result<T> {

    @ApiModelProperty("是否成功: true or false")
    private boolean success;

    @ApiModelProperty("描述性原因")
    private String message;

    @ApiModelProperty("业务数据")
    private T data;

    public Result(T data) {
        this(true, null, data);
    }

    public Result(boolean success, String message) {
        this(success, message, null);
    }

    public Result(boolean success, String message, T data) {
        this.success = success;
        this.message = message;
        this.data = data;
    }

    public static <T> Result<T> success(T data) {
        return new Result<>(true, "SUCCESS", data);
    }

    public static <T> Result<T> success(String message, T data) {
        return new Result<>(true, message, data);
    }


    public static Result failure() {
        return new Result<>(false, "FAILURE", null);
    }


    public static Result failure(String message) {
        return new Result<>(false, message, null);
    }
}
